import request from '@/utils/request'

function url(u) {
  const prefix = '/meeting'
  return `${prefix}${u || ''}`
}

// 查询自己发起的会议
export function findMeetingByMyself(page, size) {
  return request({
    url: url('/mine'),
    method: 'get',
    params: { page, size }
  })
}

// 查询自己参与的会议(不含自己发起的)
export function findMeetingByJoin(page, size) {
  return request({
    url: url('/joined'),
    method: 'get',
    params: { page, size }
  })
}

// 查询自己参与的会议(含自己发起的)
export function findMyMeeting(page, size) {
  return request({
    url: url(),
    method: 'get',
    params: { page, size }
  })
}

// 根据id查询会议
export function findMeetingById(id) {
  return request({
    url: url(`/${id}`),
    method: 'get'
  })
}

// 根据邀请码查询会议
export function findMeetingByCode(code) {
  return request({
    url: url(`/invitationCode/${code}`),
    method: 'get'
  })
}

// 生成会议邀请码
export function getInvitationCode(id) {
  return request({
    url: url(`/${id}/invitationCode`),
    method: 'post'
  })
}

// 预约会议 自动排会议室
export function bookMeetingAuto(meeting) {
  return request({
    url: url('/autoroom'),
    method: 'post',
    data: meeting
  })
}

// 预约会议 指定会议室
export function bookMeetingRoom(meeting) {
  return request({
    url: url(),
    method: 'post',
    data: meeting
  })
}

/**
 * 修改会议信息
 * @param {object} meeting
 * @param {number} meeting.id
 * @param {string} meeting.theme
 * @param {number} meeting.attendance
 * @param {string} meeting.attachment
 * @param {number} meeting.invite
 */
export function updateMeeting(meeting) {
  return request({
    url: url(),
    method: 'put',
    data: meeting
  })
}

// 查看会议室使用情况
export function checkUsage(id) {
  return request({
    url: url(`/room/${id}`),
    method: 'get'
  })
}

// 取消会议
export function cancelMeeting(id) {
  return request({
    url: url(`${id}`),
    method: 'delete'
  })
}
